#include <stdio.h>
#include <string.h>
#include "Interface.h"

int main()
{
    char input_msg[1010];
    double volts[9500];
    char output_msg[1010];

    // 输入消息, 长度不超过1000
    printf("Input message(length <= 1000): ");
    fgets(input_msg, sizeof(input_msg), stdin);

    // 编码
    int encoded_size = rs232c_encode(volts, 9500, input_msg, strlen(input_msg));
    if (encoded_size == -1)
    {
        printf("Encoding failed.\n");
        return 1;
    }

    // 输出编码后的电压值序列
    printf("Encoded voltage sequence: ");
    for (int i = 0; i < encoded_size; i++)
    {
        printf("%.1f ", volts[i]);
    }
    printf("\n");

    // 解码
    int decoded_size = rs232c_decode(output_msg, 1010, volts, encoded_size);
    if (decoded_size == -1)
    {
        printf("Decoding failed.\n");
        return 1;
    }

    // 输出解码后的消息
    printf("Decoded message: %s\n", output_msg);

    return 0;
}